package com.efast.dmom.mgmt.controller.les;


import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.entity.les.TwMovementDetails;
import com.efast.dmom.mgmt.service.les.TwMovementDetailsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ChenLiPeng
 * @since 2018-05-16
 */
@Controller
@RequestMapping("/twMovementDetails")
@Api(description = "库存移动单（明细")
public class TwMovementDetailsController {

    private final TwMovementDetailsService twMovementDetailsService;

    @Autowired
    public TwMovementDetailsController(TwMovementDetailsService twMovementDetailsService) {
        this.twMovementDetailsService = twMovementDetailsService;
    }

    @ApiOperation(value = "新增")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean line(@RequestBody TwMovementDetails twMovementDetails) {
        ResultBean result = new ResultBean(true, "'");
        twMovementDetails.setCreateTime(new Date());
        twMovementDetails.setCreateUser(SpringWebUtils.getRequestUser());
        twMovementDetails.setCompanyCode(SpringWebUtils.getRequestCompany());
        twMovementDetails.setMarkStatus(1);
        twMovementDetailsService.insert(twMovementDetails);
        result.setMessage("新增成功");
        return result;
    }

    @ApiOperation(value = "关闭")
    @RequestMapping(value = "/close", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean close(@RequestBody TwMovementDetails twMovementDetails) {
        ResultBean result = new ResultBean(true, "'");
        // 订单行状态 0新单1发布2完成3关闭4分配完成5部分分配
        twMovementDetails.setLineStatus("3");
        twMovementDetailsService.updateById(twMovementDetails);
        result.setMessage("关闭成功");
        return result;
    }

    @ApiOperation(value = "分配")
    @RequestMapping(value = "/distribution", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean distribution(@RequestBody TwMovementDetails twMovementDetails) {
        ResultBean result = new ResultBean(true, "'");
        twMovementDetailsService.insert(twMovementDetails);
        result.setMessage("分配成功");
        return result;
    }

    @ApiOperation(value = "发布")
    @RequestMapping(value = "/release", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean release(@RequestBody TwMovementDetails twMovementDetails) {
        ResultBean result = new ResultBean(true, "'");
        twMovementDetailsService.insert(twMovementDetails);
        result.setMessage("发布成功");
        return result;
    }

}

